package mvc.controller.filter;

import mvc.controller.HeaderServlet;
import mvc.model.service.ProductService;
import mvc.model.service.impl.ProductServiceImpl;
import mvc.model.vo.HeadProductVO;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebFilter(filterName = "AFilter", urlPatterns = "/index.jsp")
public class AFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        if (request.getSession().getAttribute("HeadPro") == null) {
            ProductService pro = new ProductServiceImpl();
            List<HeadProductVO> some = pro.findSome();
            request.getSession().setAttribute("HeadPro", some);
        }
        System.out.println("i");
        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
